package tw.com.softleader.reins.demo.city.service;

import java.util.ArrayList;
import java.util.List;

import tw.com.softleader.reins.demo.city.entity.City;
public class CityService {

	List<City> citylist = new ArrayList<City>();
	
	public CityService(){
		City city1 = new City();
		city1.setName("Taipei");
		city1.setPopulation(2691331);
		city1.setArea(271.1);
		citylist.add(city1);
		
		City city2 = new City();
		city2.setName("Kaohsiung");
		city2.setPopulation(2778920);
		city2.setArea(2946.5);
		citylist.add(city2);
		
		City city3 = new City();
		city3.setName("Taichung");
		city3.setPopulation(2706209);
		city3.setArea(2215.3);
		citylist.add(city3);
				
		}
	public List<City> getAll(){
		List<City> citylists = new ArrayList<City>();	
		
		for(City city :citylist){
			citylists.add(city);
		}
		return citylists;
	}
	
	public City getByName(String name){
		for(City city:citylist){
			if(city.getName().equals(name)){
				return city;
			}
		}
		return null;
	}
}
